#include"RingQueue.hpp"

#define Type int 
void* Productor(void *args)
{
  auto it = static_cast<RingQueue<Type>*>(args);
  int x;
  while(true)
  {
    x = rand() % 100;
    it->Push(x);
    cout << "Productor: " << x << endl;
    sleep(1);
  }
  return nullptr;
}

void* Consumer(void *args)
{
  auto it = static_cast<RingQueue<Type>*>(args);
  int x;
  sleep(3);
  while(true)
  {
    it->Pop(&x);    
    cout << "Consumer: " << x << endl;
    sleep(1);
  }
  return nullptr;
}
int main()
{
    RingQueue<Type>* rq = new RingQueue<Type>();
   pthread_t c[5],p[3];
   for(int i = 0;i < 5;++i)
   pthread_create(c + i,nullptr,Productor,rq);
   for(int i = 0;i < 3;++i)
   pthread_create(p + i,nullptr,Consumer,rq);

   for(int i = 0;i < 5;++i)
   pthread_join(c[i],nullptr);
  
   for(int i = 0;i < 3;++i)
   pthread_join(p[i],nullptr);
    return 0;
}